package gameUI;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ASUS
 *创建英雄战机
 */
public class Hero extends flyer{

	/*子弹库*/
	List<Fire> fires = new ArrayList<Fire>();
	
	/*英雄机的血量*/
	int hp;
	
	/*英雄机的炮火等级*/
	int grade;
	
	public Hero() {
		/*获取图片*/
		img = ImageTools.getimage("../img/hero.png");
		/*获取宽高*/
		w = img.getWidth();
		h = img.getHeight();
		/*初始化战机坐标*/
		x = 200;
		y = 550;
		/*初始化血量*/
		hp = 3;
		/*初始化炮火等级*/
		grade = 0;
	}

	/**
	 * 鼠标移动改变坐标
	 * @param mx
	 * @param my
	 */
	public void move(int mx, int my) {
		x = mx - w / 2;
		y = my - h / 2;
	}
	
	/**
	 * 创建子弹子弹库，返回子弹库的内容
	 */
	int index = 0;
	public void getFires(){
		index ++;
		/*如果调用了20次，那么就创建一颗子弹*/
		if(index % 10 == 0) {
			/*炮火等级*/
			if(grade == 0) {//中间的子弹
				/*创建中间子弹*/
				Fire center = new Fire(this.x + 45, this.y - 30);
				fires.add(center);
			}else if(grade == 1) {//两旁子弹
				/*创建左边的*/
				Fire left = new Fire(this.x + 20, this.y - 15);
				fires.add(left);
				/*创建右边的*/
				Fire right = new Fire(this.x + 70, this.y - 15);
				fires.add(right);
			}else if(grade == 2){//三排子弹
				/*创建中间子弹*/
				Fire center = new Fire(this.x + 45, this.y - 30);
				fires.add(center);
				/*创建左边的*/
				Fire left = new Fire(this.x + 20, this.y - 15);
				fires.add(left);
				/*创建右边的*/
				Fire right = new Fire(this.x + 70, this.y - 15);
				fires.add(right);
			}else if(grade == 3) {//四排子弹
				/*创建中间子弹*/
				Fire center1 = new Fire(this.x + 30, this.y - 30);
				fires.add(center1);
				Fire center2 = new Fire(this.x + 60, this.y - 30);
				fires.add(center2);
				/*创建左边的*/
				Fire left = new Fire(this.x + 10, this.y - 15);
				fires.add(left);
				/*创建右边的*/
				Fire right = new Fire(this.x + 80, this.y - 15);
				fires.add(right);
			}else if(grade == 4) {//五排子弹
				/*创建中间子弹*/
				Fire center = new Fire(this.x + 45, this.y - 30);
				fires.add(center);
				/*创建左边的*/
				Fire left = new Fire(this.x + 20, this.y - 15);
				fires.add(left);
				/*创建右边的*/
				Fire right = new Fire(this.x + 70, this.y - 15);
				fires.add(right);
				/*创建左边的*/
				Fire left1 = new Fire(this.x - 5, this.y);
				fires.add(left1);
				/*创建右边的*/
				Fire right1 = new Fire(this.x + 95, this.y);
				fires.add(right1);
			}
		}
	}

	public boolean hit(Ep e) {
		/*如果碰撞到敌机*/
		if(e.x - w <= x &&
				e.x + e.w >= x &&
				e.y - h <= y &&
				e.y + e.h >= y) {
			return true;//碰撞
		}
		return false;//游戏默认未碰撞
	}
	
	
}
